home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / maxsgames.lha / MaxGames / Drag.lha / drag.c < prev   
C/C++ Source or Header  |  1991-03-15  |  15KB  |  463 lines

  1. #if LATTICE
  2. #include <proto/exec.h>
  3. #else
  4. #include <functions.h>
  5. #endif
  6. #include <exec/exec.h>
  7. #include <fcntl.h>
  8. #include <stdio.h>
  9.  
  10. #include <stdlib.h>
  11.         
  12.         long money;
  13.         short win;
  14.         short car1,car2,car3;
  15.         short odd1,odd2,odd3;
  16.         short bet;
  17.         long  amount_bet;
  18.         char cars1[] = "\\_/~\\ ";
  19.         char car_1[] = "(O)~O>";
  20.         char cars2[] = "/|_|\\ [2]";
  21.         char car_2[] = "\\O==O}";
  22.         char cars3[] = "[\\/~\\_[3]";
  23.         char car_3[] = "\\O==o/";
  24.         char newcar[10];
  25.         char cont[10];
  26.         char text[80];
  27.  
  28. #define CAR if(doormsg->carrier==1) return;
  29. #define DROP if(doormsg->carrier==1) end();
  30.  
  31. struct DoorMsg {
  32.     struct Message Door_Msg;
  33.     short command;
  34.     short data;
  35.     char string[80];
  36.     short carrier;
  37.     };
  38.  
  39. struct DoorMsg *doormsg,*garbage;
  40. struct MsgPort *MyPort,*replyport;
  41.  
  42. extern void getsvar();
  43. extern void sendmessage();
  44. extern void hotkey();
  45. extern void prompt();
  46. extern void sprompt();
  47. extern void showfile();
  48. extern void end();
  49. extern void cls();
  50.  
  51. struct Task *mytask; /* Pointer to this task so we can name it */
  52.  
  53. int err;
  54.  
  55. main(argc,argv)
  56. int argc;
  57. char *argv[];
  58. {
  59.     char username[81],line_number;
  60.     char tmp[81],str[81];
  61.     char doorspath[80];
  62.     char rportname[10],cportname[12];    /* ReplyPort and Control Port names */
  63.     int num,numq,numa;
  64.     short answers[26][21];
  65.     int coun,coun2,inn,tota;
  66.     int polln;
  67.     int fd;
  68.     FILE *fp,*fopen();
  69.     float percent;
  70.     
  71.     /* Pull out the line number from the argv field to find where we are */
  72.     
  73.     line_number=argv[1][0];
  74.     
  75.     mytask=FindTask(0L);
  76.     mytask->tc_Node.ln_Name = "Drag Race V0.90";    /* You'll probably want to
  77.                              change the name to the
  78.                              name of whatever your door
  79.                              is! */
  80.     
  81.     /* Create the Reply port, with the name based on the number...
  82.  
  83.        Attempts at doing this with a simple "sprintf" failed, causing
  84.        the creation of garbled portnames.  This works fine.  Stick with
  85.            it.  */
  86.  
  87.     switch(line_number){
  88.         case '0':    replyport=CreatePort("DoorReply0",0L); break;
  89.         case '1':    replyport=CreatePort("DoorReply1",0L); break;
  90.         case '2':    replyport=CreatePort("DoorReply2",0L); break;
  91.         case '3':    replyport=CreatePort("DoorReply3",0L); break;
  92.         case '4':    replyport=CreatePort("DoorReply4",0L); break;
  93.         case '5':    replyport=CreatePort("DoorReply5",0L); break;
  94.         case '6':    replyport=CreatePort("DoorReply6",0L); break;
  95.         case '7':    replyport=CreatePort("DoorReply7",0L); break;
  96.         case '8':    replyport=CreatePort("DoorReply8",0L); break;
  97.         case '9':    replyport=CreatePort("DoorReply9",0L); break;
  98.     }
  99.     
  100.     doormsg=(struct DoorMsg *)AllocMem((long)sizeof(*doormsg),MEMF_PUBLIC);
  101.     
  102.     if(doormsg==0)
  103.     {
  104.         puts("Couldn't allocate DoorMsg!");
  105.         return;
  106.     }
  107.     
  108.     doormsg->Door_Msg.mn_Node.ln_Type = NT_MESSAGE;
  109.     doormsg->Door_Msg.mn_ReplyPort = replyport;
  110.     doormsg->Door_Msg.mn_Length = (UWORD)sizeof(*doormsg);
  111.     
  112.     /* Locate the correct DoorControl port based on the line number */
  113.     
  114.     sprintf(cportname,"DoorControl%c",line_number);
  115.        MyPort=FindPort(cportname);
  116.        if(MyPort==0L) 
  117.     {
  118.         puts("DoorControl port not located!");
  119.         FreeMem(doormsg,(long)sizeof(*doormsg));
  120.         return;
  121.     }
  122.     
  123.     /* Now for the main program area - see below for explanations of
  124.        getsvar, sendmessage, and hotkey (as well as many more). */
  125.         sendmessage("************************************************",1);
  126.         sendmessage("*       D R A G   R A C I N G   V 0.90         *",1);
  127.         sendmessage("*                                              *",1);
  128.         sendmessage("*     P A R A G O N   V E R S I O N   B Y      *",1);
  129.         sendmessage("*                                              *",1);
  130.         sendmessage("*     D.  Z A K I  K A R A C H I W A L A       *",1);
  131.         sendmessage("*                                              *",1);
  132.         sendmessage("*       O N   M A R C H  1 5  1 9 9 1          *",1);
  133.         sendmessage("************************************************",1);
  134.         sendmessage("",1);
  135.          
  136.         win = 50;
  137.         money = 50;
  138.         sendmessage("",1);
  139.         sendmessage("Current Team Car:",1);
  140.         sendmessage("_________________",1);
  141.         sendmessage("",1);
  142.         sendmessage(cars1,1);
  143.         sendmessage(car_1,1);
  144.         sendmessage("",1);
  145.         hotkey("Do you want to make a new car ?",newcar);
  146.         DROP;
  147.         if (toupper(newcar[0]) == 'Y')
  148.             {
  149.                 sendmessage("",1);
  150.                 sendmessage("Design your car (Max 6 Characters/Top & Bottom)");
  151.                 sendmessage("",1);
  152.                 sendmessage("",1);
  153.                 sendmessage("Current Car Body Roof");
  154.                 sendmessage("",1);
  155.                 sendmessage(cars1,1);
  156.                 prompt(">",cars1,7);
  157.                 DROP;
  158.                 strncpy(cars1,cars1,6);
  159.                 sendmessage("",1);
  160.                 sendmessage("Current Car Body Base");
  161.                 sendmessage("",1);
  162.                 sendmessage(car_1,1);
  163.                 prompt(">",car_1,7);
  164.                 DROP;
  165.                 strncpy(cars1,car_1,6);
  166.                 
  167.              }
  168.          
  169.         while (money > 0 && toupper(cont[0]) != 'N')
  170.             {
  171.                 
  172.                 car1 = 0;
  173.                 car2 = 0;
  174.                 car3 = 0;
  175.                 cls();
  176.  
  177.                 /* Number = rand() % range + 2 */
  178.                 odd1 = rand() % 3 +2;odd2 = rand() % 3+2;odd3 = rand() % 3+2;
  179.  
  180.                 sendmessage("",1);
  181.                 sendmessage("Pete Rose's Drag Race Pool",1);
  182.                 sendmessage("-=-=-=-=-=-=-=-=-=-=-=-=-=",1);
  183.                 sendmessage("Car            |    Odds      |",1);
  184.                 sendmessage("-------------------------------",1);
  185.                 sendmessage("",1);
  186.                 sprintf(text," %s[1]     |    %d:1       |    (Your Race Team)",
  187.                        cars1,odd1); 
  188.                 sendmessage(text,1);
  189.                 sprintf(text," %s        |              |",car_1);
  190.                 sendmessage(text,1);
  191.                 sprintf(text," %s     |    %d:1       |",cars2,odd2); 
  192.                 sendmessage(text,1);
  193.                 sprintf(text," %s        |              |",car_2);
  194.                 sendmessage(text,1);
  195.                 sprintf(text," %s     |    %d:1       |",cars3,odd3); 
  196.                 sendmessage(text,1);
  197.                 sprintf(text," %s        |              |",car_3);
  198.                 sendmessage(text,1);
  199.                 sendmessage("-------------------------------",1);
  200.                 sendmessage("",1);
  201.                 sendmessage("",1);
  202.                 sprintf(text,"Currently You Have ($%d) In Your Wallet",money);
  203.                 sendmessage(text,1);
  204.                 sendmessage("",1);
  205.                 hotkey("What Race Team Do You Want To Bet On (1(Yours),2,3) ?",text);
  206.                 DROP;
  207.                 bet = atoi(text);
  208.                 if (bet != 1 && bet != 2 && bet != 3)
  209.                     bet = 1;
  210.                 sendmessage("",1);
  211.                 sendmessage("",1);
  212.                 prompt("Enter Amount You Want To Bet (Minimum 1) $",text,6);
  213.                 DROP;
  214.                 amount_bet = atoi(text);
  215.                 if ( amount_bet < 1 )
  216.                     amount_bet = 1;
  217.                 else if (amount_bet > money)
  218.                     amount_bet = money;
  219.                 cls();
  220.                 while (car1<win || car2<win || car3<win)
  221.                     {
  222.                         sprintf(text,"\033[1;%dH      ",car1);
  223.                         sendmessage(text,0);
  224.                         sprintf(text,"\033[2;%dH___",car1);
  225.                         sendmessage(text,1);
  226.                         sprintf(text,"\033[4;%dH      ",car2);
  227.                         sendmessage(text,0);
  228.                         sprintf(text,"\033[5;%dH___",car2);
  229.                         sendmessage(text,0);
  230.                         sprintf(text,"\033[7;%dH      ",car3);
  231.                         sendmessage(text,0);
  232.                         sprintf(text,"\033[8;%dH___",car3);
  233.                         sendmessage(text,0);
  234.                         
  235.                         car1 = car1 + rand() % 4;
  236.                         car2 = car2 + rand() % 4;
  237.                         car3 = car3 + rand() % 4;
  238.                         sprintf(text,"\033[1;%dH%s[1]",car1,cars1);
  239.                         sendmessage(text,0);
  240.                         sprintf(text,"\033[2;%dH%s",car1,car_1);
  241.                         sendmessage(text,0);
  242.                         sprintf(text,"\033[4;%dH%s",car2,cars2);
  243.                         sendmessage(text,0);
  244.                         sprintf(text,"\033[5;%dH%s",car2,car_2);
  245.                         sendmessage(text,0);
  246.                         sprintf(text,"\033[7;%dH%s",car3,cars3);
  247.                         sendmessage(text,0);
  248.                         sprintf(text,"\033[8;%dH%s",car3,car_3);
  249.                         sendmessage(text,0);
  250.                     }
  251.                 if (car1>=car2)
  252.                     {
  253.                         if (car1>=car3)
  254.                             {
  255.                                 cls();
  256.                                 sendmessage("Car 1 Is First",1);
  257.                                 sendmessage("",1);
  258.                                 sendmessage("",1);
  259.                                 if (bet == 1)
  260.                                 {   sendmessage("You Win Big Time!!!!",1);
  261.                                     money = money + amount_bet*odd1;
  262.                                 }
  263.                                 else
  264.                                 {   sendmessage("You LOOSE BIG TIME!!!!",1);
  265.                                     money = money - amount_bet;
  266.                                 }
  267.  
  268.                             }
  269.  
  270.                         else
  271.                             {
  272.                                 cls();
  273.                                 sendmessage("Car 3 Is First",1);
  274.                                 sendmessage("",1);
  275.                                 sendmessage("",1);
  276.                                 if (bet == 3)
  277.                                 {   sendmessage("You Win Big Time!!!!",1);
  278.                                     money = money + amount_bet*odd3;
  279.                                 }
  280.                                 else
  281.                                 {   sendmessage("You LOOSE BIG TIME!!!!",1);
  282.                                     money = money - amount_bet;
  283.                                 }
  284.  
  285.                             }
  286.  
  287.                     }
  288.  
  289.                 else if (car2 >= car3)
  290.                     {
  291.                         cls();
  292.                         sendmessage("Car 2 Is First",1);
  293.                         sendmessage("",1);
  294.                         sendmessage("",1);
  295.                         if (bet == 2)
  296.                            {   sendmessage("You Win Big Time!!!!",1);
  297.                                money = money + amount_bet*odd2;
  298.                            }
  299.                         else
  300.                            {   sendmessage("You LOOSE BIG TIME!!!!",1);
  301.                                money = money - amount_bet;
  302.                            }
  303.  
  304.                      }
  305.  
  306.                 else
  307.                     {
  308.                         cls();
  309.                         sendmessage("Car 3 Is First",1);
  310.                         sendmessage("",1);
  311.                         sendmessage("",1);
  312.                         if (bet == 3)
  313.                            {   sendmessage("You Win Big Time!!!!",1);
  314.                                money = money + amount_bet*odd3;
  315.                            }
  316.                         else
  317.                            {   sendmessage("You LOOSE BIG TIME!!!!",1);
  318.                                money = money - amount_bet;
  319.                            }
  320.                      }
  321.                 if (money > 0) {
  322.                     hotkey("Would you like to continue (Y/N) ?",cont);
  323.                     DROP;
  324.                 }
  325.  
  326.       
  327.     }
  328.  
  329. end();
  330. }
  331. void cls()
  332.     
  333.     {
  334.         int i;    
  335.         for(i=1;i <= 24;i++)
  336.           sendmessage("",1);
  337.             
  338.     }    
  339.     
  340. void end()
  341. {
  342.     doormsg->command = 20;
  343.     PutMsg(MyPort,(struct Message *)doormsg);
  344.     (void)WaitPort(replyport);
  345.     (void)GetMsg(replyport);
  346.     FreeMem(doormsg,(long)sizeof(*doormsg));
  347.     DeletePort(replyport);
  348.     exit(0);
  349. }
  350.  
  351. /*
  352.  * getsvar(typ,mstring) - Gets certain string variables from Paragon.
  353.  * "mstring" is a pointer to a string to dump the string into.  "typ" tells
  354.  * it what you want: 1=Name, 2=Password, 3=Address, 4=City, 5=State
  355.  * 6=Postal code, 7=Door pathname, 8=Default BBS pathname.
  356.  */
  357.  
  358. void getsvar(typ,mstring)
  359. int typ;
  360. char *mstring;
  361. {
  362.     doormsg->data = typ;
  363.     doormsg->command = 14;
  364.     PutMsg(MyPort,(struct Message *)doormsg);
  365.     (void)WaitPort(replyport);
  366.     strcpy(mstring,doormsg->string);
  367.     (void)GetMsg(replyport);
  368. }
  369.  
  370. /*
  371.  * sendmessage(mstring,nl) - Sends a message to the local window and to
  372.  * the modem (if applicable).  "mstring" is the output string you want to
  373.  * send, "nl" is and integer which is 1 if you want it to send the
  374.  * c/r+l/f combination, or 0 if not.
  375.  */
  376.  
  377. void sendmessage(mstring,nl)
  378. char mstring[];
  379. int nl;
  380. {
  381.     doormsg->data = nl;
  382.     doormsg->command = 1;
  383.     strcpy(doormsg->string,mstring);
  384.     PutMsg(MyPort,(struct Message *)doormsg);
  385.     (void)WaitPort(replyport);
  386.     (void)GetMsg(replyport);
  387. }
  388.  
  389. /*
  390.  * hotkey(mstring,ostring) - outputs the string "mstring" and waits
  391.  * for one key which it will place in element [0] of "ostring".
  392.  * "mstring" may be a null string, in which case it will only wait for
  393.  * the key, and not output any prompt.
  394.  */
  395.  
  396. void hotkey(mstring,ostring)
  397. char mstring[];
  398. char *ostring;
  399. {
  400.     strcpy(doormsg->string,mstring);
  401.     doormsg->command = 8;
  402.     PutMsg(MyPort,(struct Message *)doormsg);
  403.     (void)WaitPort(replyport);
  404.     (void)GetMsg(replyport);
  405.     strcpy(ostring,doormsg->string);
  406. }
  407.  
  408. /*
  409.  * prompt(mstring,ostring,len) - outputs the string "mstring" and inputs
  410.  * a string which is placed in ostring.  'len' is the maximum number of
  411.  * characters which will be accepted.
  412.  */
  413.  
  414. void prompt(mstring,ostring,len)
  415. char mstring[];
  416. char *ostring;
  417. int len;
  418. {
  419.     strcpy(doormsg->string,mstring);
  420.     doormsg->data=len;
  421.     doormsg->command = 6;
  422.     PutMsg(MyPort,(struct Message *)doormsg);
  423.     (void)WaitPort(replyport);
  424.     (void)GetMsg(replyport);
  425.     strcpy(ostring,doormsg->string);
  426. }
  427.  
  428. /* sprompt is the same as prompt, except it will accept stacked commands
  429.  * (with the '/' key) and will send back any stacked command which is
  430.  * currently in the command buffer instead of waiting for input from the
  431.  * user.  It will even accept stacked commands which bridged over from the
  432.  * BBS.
  433.  */
  434.  
  435. void sprompt(mstring,ostring,len)
  436. char mstring[];
  437. char *ostring;
  438. int len;
  439. {
  440.     strcpy(doormsg->string,mstring);
  441.     doormsg->data=len;
  442.     doormsg->command = 7;
  443.     PutMsg(MyPort,(struct Message *)doormsg);
  444.     (void)WaitPort(replyport);
  445.     (void)GetMsg(replyport);
  446.     strcpy(ostring,doormsg->string);
  447. }
  448.  
  449. /* showfile(mstring) shows the text file which mstring is the path to.
  450.    It handles ^C aborting, and ^S/^Q pausing. */
  451.  
  452. void showfile(mstring)
  453. char mstring[];
  454. {
  455.     strcpy(doormsg->string,mstring);
  456.     doormsg->command = 10;
  457.     PutMsg(MyPort,(struct Message *)doormsg);
  458.     (void)WaitPort(replyport);
  459.     (void)GetMsg(replyport);
  460. }
  461.  
  462.  
  463.